<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
  <meta charset="utf-8">
  <title>员工日报</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <link rel="stylesheet" href="../layuimini/lib/layui-v2.6.3/css/layui.css" media="all">
  <link rel="stylesheet" href="../layuimini/css/public.css" media="all">
  <link rel="stylesheet" href="../layuimini/css/public.css" media="all">
  <style type="text/css">
    .layui-form-select .layui-input {
      width: 190px;
      cursor: pointer;
    }
  </style>
</head>
<body>
<form method="post" class="layui-form" action="">
    <input type="hidden" id="count" th:value="${count}">
  <div class="layui-form-item">
      <div class="layui-inline">
        <label class="layui-form-label">个人计划</label>
        <div class="layui-input-inline">
          <select name="pid" id="select" class="layui-input"  >
            <option th:each="d:${plans}"  th:value="${d.id}" th:text="${d.theme}"></option>
          </select>
        </div>
      </div>
      <br/>
      <div class="layui-inline">
        <label class="layui-form-label">工作日期</label>
        <div class="layui-input-inline">
          <input type="date" lay-verify="required" class="layui-input" name="dailydate" id="kaishi">
        </div>
      </div>
      <br/>
      <div class="layui-inline">
        <label class="layui-form-label">工作内容</label>
        <div class="layui-input-inline">
          <textarea name="dailytext" style="width: 190px;height: 80px;"></textarea>
        </div>
          <label style="color: red;display: none" id="dailytext">请填写今日完成的内容</label>
      </div>
      <br/>
      <div class="layui-inline">
        <label class="layui-form-label">完成进度</label>
        <div class="layui-input-inline">
          <input class="layui-input" type="number" name="schedule" max="100" min="1">
        </div>
        <label style="color: red;display: none" id="schedule">请填写今日进度</label>
      </div>
      <br/>
      <div class="layui-form-item">
        <div class="layui-input-block">
          <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">提交</button>
        </div>
      </div>
  </div>
</form>
<script src="../layuimini/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script>
  var $ = layui.jquery;
  $(function () {
    //获取当前时间
    var dateone =new Date();
    //获取当前年份
    var year =dateone.getFullYear();
    //获取当前月份
    var month = dateone.getMonth()+1<10 ? "0"+(dateone.getMonth()+1):(dateone.getMonth()+1);
    //获取当前日期
    var date =dateone.getDate()<10 ? "0"+dateone.getDate():dateone.getDate();

    $("#kaishi").attr("max",year+"-"+month+"-"+date);
    $("#kaishi").attr("min",year+"-"+month+"-"+date);
  })

  function today(){
    var today=new Date();//new 出当前时间
    var h=today.getFullYear();//获取年
    var m=today.getMonth()+1;//获取月
    var d=today.getDate();//获取日
    var H = today.getHours();//获取时
    var M = today.getMinutes();//获取分
    var S = today.getSeconds();//获取秒
    return h+"-"+m+"-"+d+" "+H+":"+M+":"+S; //返回 年-月-日 时:分:秒
  }
  $(":input[name='dailydate']").val(today());

  layui.use(['form'], function () {

    var form = layui.form;
    var table = layui.table;
    //监听提交
    form.on('submit(saveBtn)', function (data) {

        let oid=$("#select").val();
       if (oid==null || oid==""){
           alert("请接取任务后填写");
       }else{
           var text=$(":input[name='dailytext']").val();
           if (text==null || text==""){
               $("#dailytext").show();
           }
           $(":input[name='dailytext']").click(function (){
               $("#dailytext").hide();
           })
           var schedule=$(":input[name='schedule']").val();
           if (schedule==null || schedule==""){
               $("#schedule").show();
           }
           $(":input[name='dailytext']").click(function (){
               $("#schedule").hide();
           })
           console.log(data.field);
           $.post('/daily/insert',data.field,function(res){
               if(res.data==="success"){
                   var iframeIndex = parent.layer.getFrameIndex(window.name);
                   parent.layer.close(iframeIndex);
                   parent.layui.table.reload('table-user');
                   parent.layer.msg(res.msg);
               }
           })
       }
      return false;
    });
  });
</script>
</body>
</html>